package com.corpgovernment.organization.convert;

import com.corpgovernment.api.organization.model.idcard.UserIdCardVo;
import com.corpgovernment.common.dto.UserCardValidationInfoReqVo;
import com.corpgovernment.common.utils.DateUtil;
import com.corpgovernment.organization.model.FfpAddRequest;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * 身份证件信息转换
 *
 * @author tkang
 */
@Component
public class UserCardInfoConvert {

    public UserCardValidationInfoReqVo convertToUserCardValidationInfo(UserIdCardVo userIdCardVo) {
        if (Objects.isNull(userIdCardVo)) {
            return null;
        }
        UserCardValidationInfoReqVo userCardInfoValidationReqVo = new UserCardValidationInfoReqVo();
        userCardInfoValidationReqVo.setCardNo(userIdCardVo.getCardNo());
        userCardInfoValidationReqVo.setCardType(userIdCardVo.getCardType());
        userCardInfoValidationReqVo.setTimeLimit(userIdCardVo.getTimeLimit());
        return userCardInfoValidationReqVo;
    }

    public UserCardValidationInfoReqVo cardInfoConvertToUserCardValidationInfo(FfpAddRequest.CardInfo cardInfo) {
        if (Objects.isNull(cardInfo)) {
            return null;
        }
        UserCardValidationInfoReqVo userCardInfoValidationReqVo = new UserCardValidationInfoReqVo();
        userCardInfoValidationReqVo.setCardNo(cardInfo.getCardId());
        userCardInfoValidationReqVo.setCardType(cardInfo.getCardType());
        userCardInfoValidationReqVo.setTimeLimit(DateUtil.stringToDate(cardInfo.getValidDate(), DateUtil.DF_YMD));
        return userCardInfoValidationReqVo;
    }
}
